package com.bestcem.xm.user.config.properties;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;


/**
 * 相关配置信息
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/26 10:21
 */
@Component
@Data
public class SettingProperties {

    @PostConstruct
    private void init() {
        this.testWhitePhoneList = Arrays.asList(testPhoneWhiteLists.split(","));
        this.forbiddenOrgCodeList = Arrays.asList(forbiddenOrgCodes.split(","));
        this.redPaperPlatformCode = initRedPaperPlatformCode();
    }

    @Autowired
    private SingleOrgProperties singleOrgProperties;

    /**
     * 默认平台代码
     */
    public static final String DEFAULT_PLATFORM_CODE = "bestcem";

    /**
     * 是否是基线
     */
    @Value("${app.xm.is-baseline:true}")
    private Boolean baselineFlag;

    /**
     * # 如果 SaaS | 引擎 == "clickhouse"，展示新旧数据看板切换按钮
     * # NP_SHOW = IS_XM or DEFAULT_WORKTABLE_ENGINE == "clickhouse"
     */
    @Value("${app.user.setting.np_show}")
    private Boolean npShow;

    /**
     * 平台
     */
    @Value("${app.user.setting.platform:xm}")
    private String platform;

    /**
     * 默认销售手机号，默认davis
     */
    @Value("${app.user.setting.defaultMobile:13585859806}")
    private String defaultMobile;

    @Value("${app.user.setting.xm_name:倍市得CEM}")
    private String xmName;

    @Value("${app.user.server.xm_server_host:xm-test.bestcem.com}")
    private String xmServerHost;

    @Value("${app.user.server.protocol:http}")
    private String serverProtocol;

    @Value("${app.user.server.sass_server_url:http://cloud-dev.bestcem.cn}")
    private String sassServerUrl;

    @Value("${app.user.magic_pwd}")
    private String magicPassword;

    @Value("${app.user.sign.bestcem_email}")
    private String bestcemEmailSign;

    public String getBestcemEmailSign() {
        return StringUtils.isBlank(bestcemEmailSign) ? xmName : bestcemEmailSign;
    }

    @Value("${app.user.sign.bestcem_sms}")
    private String bestcemSmsSign;

    public String getBestcemSmsSign() {
        return StringUtils.isBlank(bestcemSmsSign) ? xmName : bestcemEmailSign;
    }

    /**
     * biz host 一般不用修改和配置, 末尾不需要加/
     */
    @Value("${app.user.bizUrl:http://biz.wenjuan.com}")
    private String bizUrl;

    /**
     * 测试手机号白名单
     */
    @Value("${app.user.testMobileWhiteList:18896813082,17839236545,17315903304,18614981109,17639839880}")
    private String testPhoneWhiteLists;

    private List<String> testWhitePhoneList;

    /**
     * 禁用的公司代码
     */
    @Value("${app.user.forbiddenOrgCodeList:www,blog,rs0,img0}")
    private String forbiddenOrgCodes;

    private List<String> forbiddenOrgCodeList;

    /**
     * 平台代码
     */
    @Value("${app.user.redPaperPlatformCode:}")
    private String redPaperPlatformCode;

    /**
     * 初始化平台代码
     *
     * @return String
     * @author wangyunyun <yunyun.wang@idiaoyan.com>
     * @date 2022/5/16 15:33
     */
    private String initRedPaperPlatformCode() {
        if (StringUtils.isNotBlank(this.redPaperPlatformCode)) {
            return this.redPaperPlatformCode;
        }
        if (this.singleOrgProperties != null && StringUtils.isNotBlank(singleOrgProperties.getCode())) {
            return singleOrgProperties.getCode();
        }
        return DEFAULT_PLATFORM_CODE;
    }

    /**
     * 用户回传数据api接口token
     */
    @Value("${app.user.baiduOcpc.token}")
    private String baiduOcpcToken;

    /**
     * 用户回传数据api接口url
     */
    @Value("${app.user.baiduOcpc.uploadConvertDataUrl}")
    private String baiduOcpcUploadConvertDataUrl;

    /**
     * 螺丝帽验证接口apiKey
     */
    @Value("${app.user.luosimao.apiKey}")
    private String luosimaoApiKey;

    /**
     * 螺丝帽验证接口 api
     */
    @Value("${app.user.luosimao.siteUerifyUrl:http://captcha.luosimao.com/api/site_verify}")
    private String luosimaoSiteUerifyUrl;

    @Value("${app.user.app.env:local}")
    private String appEnv;

    @Value("${app.user.app.name:CEM}")
    private String appName;

    @Value("${app.user.best_hotline:400-618-8166 转 211}")
    private String bestHotline;

    /**
     * IS_XM = APP_NAME == "XM"
     */
    public Boolean getIsXm() {
        return Boolean.FALSE;
    }

    /**
     * 是否为基线 true:是 false:不是
     */
    public Boolean isBaseLine() {
        return Boolean.TRUE;
    }

}
